在DAY 25裡是將弱掃報告清單透過Regex轉成CSV格式以便貼上Excel。今天情況相同,客戶要求提供一份Excel過版清單,記錄路徑及名稱,所以用Perl:
#!/usr/bin/perl
use File::Find qw(finddepth);
my $fcb = "/Users/jemmy/Downloads/SpringBootTutorial-Ch18-1/src";
finddepth(sub {
my $fname = $File::Find::name;
my @ary = split/\t/;
return if ($ary[-1] =~ /^[.].*/); # 遇.及..跳過
my $dir = "MyProject/" . substr($fname, length($fcb) + 1, length($fname) - length($fcb) - 2 - length($ary[-1]));
my @tst = split(".", $ary[-1]);
print "2024/10/11\tMyProject\tPROD\t9527\t$dir\t$ary[-1]\n" unless (-d $fname);
}, $fcb);
前四個欄位為固定內容,包括過版日期、專案名、環境、issue單號,後面兩個欄位則是遞迴讀檔案清單:路徑及檔名。
得到內容如下,然後複製貼上Excel
2024/10/11 MyProject PROD 9527 MyProject/main/resources application.properties
2024/10/11 MyProject PROD 9527 MyProject/main/java/com/vincent/demo DemoController.java
2024/10/11 MyProject PROD 9527 MyProject/main/java/com/vincent/demo SecurityConfig.java
2024/10/11 MyProject PROD 9527 MyProject/main/java/com/vincent/demo Application.java
2024/10/11 MyProject PROD 9527 MyProject/main/java/com/vincent/demo UserRepository.java
2024/10/11 MyProject PROD 9527 MyProject/main/java/com/vincent/demo/model AppUser.java
2024/10/11 MyProject PROD 9527 MyProject/main/java/com/vincent/demo/model LoginRequest.java
2024/10/11 MyProject PROD 9527 MyProject/main/java/com/vincent/demo/model UserAuthority.java
2024/10/11 MyProject PROD 9527 MyProject/main/java/com/vincent/demo/model LoginResponse.java
2024/10/11 MyProject PROD 9527 MyProject/main/java/com/vincent/demo/service TokenService.java
2024/10/11 MyProject PROD 9527 MyProject/main/java/com/vincent/demo/service UserDetailsServiceImpl.java